package com.oracle.rentcar.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.oracle.rentcar.mapper.EmpMapper;
import com.oracle.rentcar.pojo.Emp;
import com.oracle.rentcar.service.EmpService;
import com.oracle.rentcar.util.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Service
public class EmpServiceImpl implements EmpService {

    @Autowired
    private EmpMapper empMapper;


    @Override
    public PageInfo<Map<String, Object>> selectEmpByParam(int currentPageNumber, String param) {
        PageHelper.startPage(currentPageNumber, Constant.PAGE_SIZE);

        List<Map<String, Object>> maps = empMapper.selectEmpByParam(param);

        PageInfo<Map<String,Object>> pageInfo = new PageInfo<>(maps);

        return pageInfo;
    }

    @Override
    public Map<String, Object> login(Emp emp) {
        Map<String, Object> map = empMapper.empLogin(emp);

        return map;
    }

    @Override
    public int deleteById(Integer id) {
        return empMapper.deleteEmpById(id);
    }

    @Override
    public int batchDeleteByIds(Integer[] empids) {
        return empMapper.batchDeleteEmp(Arrays.asList(empids));
    }

    @Override
    public Emp selectById(int id) {
        return empMapper.selectEmpById(id);
    }

    @Override
    public int updateEmpById(Emp emp) {
        return empMapper.updateEmpById(emp);
    }
}
